package com.zr.controller;


import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zr.model.Cp_xxd;
import com.zr.model.Customer;
import com.zr.model.Restaurant_spd;
import com.zr.service.LoginService;
import com.zr.service.RestaurantService_spd;
import com.zr.service.ShowService;
import com.zr.serviceimp.LoginServiceImpl;
import com.zr.serviceimp.RestaurantServiceImpl_spd;
import com.zr.serviceimp.ShowServiceImpl;

/**
 * 登录
 * @author 柏小毛
 *
 */
public class LoginController extends HttpServlet{
	LoginService   ls = new LoginServiceImpl();
	RestaurantService_spd rs = new RestaurantServiceImpl_spd();
	ShowService ss = new ShowServiceImpl();
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	// TODO Auto-generated method stub
		doPost(req, resp);
}

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	// TODO Auto-generated method stub
		req.setCharacterEncoding("utf8");
		HttpSession session = req.getSession();
		String uname = req.getParameter("uname");
		String upsdw = req.getParameter("upswd");
		List<Restaurant_spd> rests = rs.getAllRestaurantMessage();
		session.setAttribute("rests", rests);
	  	Customer cs=ls.getCubyName(uname);
	  	session.setAttribute("customerly", cs);
	  boolean  flag = ls.validateUser(uname, upsdw);
	  if(flag){
		  session.setAttribute("uname", uname);
		  req.getRequestDispatcher("main.jsp").forward(req, resp);
	  }else{
		  req.getRequestDispatcher("index.jsp").forward(req, resp);
	  }
}
}

